<?php

/**
 * Lettre filter form base class.
 *
 * @package    symfony
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 29570 2010-05-21 14:49:47Z Kris.Wallsmith $
 */
abstract class BaseLettreFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'numero'         => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'feuillet_debut' => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'feuillet_fin'   => new sfWidgetFormFilterInput(),
      'description'    => new sfWidgetFormFilterInput(),
      'contenu'        => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'volume_id'      => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Volume'), 'add_empty' => true)),
      'origine_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Origine'), 'add_empty' => true)),
      'personnes_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Personne')),
      'navires_list'   => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Navire')),
    ));

    $this->setValidators(array(
      'numero'         => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'feuillet_debut' => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'feuillet_fin'   => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'description'    => new sfValidatorPass(array('required' => false)),
      'contenu'        => new sfValidatorPass(array('required' => false)),
      'volume_id'      => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Volume'), 'column' => 'id')),
      'origine_id'     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Origine'), 'column' => 'id')),
      'personnes_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Personne', 'required' => false)),
      'navires_list'   => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Navire', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('lettre_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addPersonnesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LettrePersonne LettrePersonne')
      ->andWhereIn('LettrePersonne.personne_id', $values)
    ;
  }

  public function addNaviresListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query
      ->leftJoin($query->getRootAlias().'.LettreNavire LettreNavire')
      ->andWhereIn('LettreNavire.navire_id', $values)
    ;
  }

  public function getModelName()
  {
    return 'Lettre';
  }

  public function getFields()
  {
    return array(
      'id'             => 'Number',
      'numero'         => 'Number',
      'feuillet_debut' => 'Number',
      'feuillet_fin'   => 'Number',
      'description'    => 'Text',
      'contenu'        => 'Text',
      'volume_id'      => 'ForeignKey',
      'origine_id'     => 'ForeignKey',
      'personnes_list' => 'ManyKey',
      'navires_list'   => 'ManyKey',
    );
  }
}
